﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using CapaEntidades;

namespace CapaDatos
{
    public class daModoPago
    {
        public static List<enModoPago> modoPagoLista()
        {
            SqlConnection cn = null;
            SqlCommand cmd = null;
            SqlDataReader dr = null;
            List<enModoPago> lstModPago = null;
            try
            {
                cn = Conexion.getConexion();
                cmd = new SqlCommand("select * from VE_modoPago", cn);
                cmd.CommandType = CommandType.Text;
                cn.Open();
                dr = cmd.ExecuteReader();
                lstModPago = new List<enModoPago>();
                while (dr.Read())
                {
                    enModoPago modPago = new enModoPago();
                    modPago.modPag_id = Convert.ToInt32(dr[0].ToString());
                    modPago.modPag_nombre = dr[1].ToString();
                    lstModPago.Add(modPago);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                dr.Close();
                cn.Close();
            }
            return lstModPago;

        }

        public static enAlerta spInsertaPedidoXML(String xml)
        {
            SqlConnection cn = null;
            SqlCommand cmd = null;
            SqlDataReader dr = null;
            enAlerta lstProducto = new enAlerta();
            try
            {

                cn = Conexion.getConexion();
                cmd = new SqlCommand("spInsertaPedidoXML", cn);
                cmd.Parameters.AddWithValue("@prmXML", xml);
                cmd.CommandType = CommandType.StoredProcedure;
                cn.Open();
                dr = cmd.ExecuteReader();
                lstProducto.val = -1;
                if (dr.Read())
                {

                    lstProducto.val = Convert.ToInt16(dr[0].ToString());
                    lstProducto.msg = "Registro Correcto";

                }
            }
            catch (Exception)
            {
                lstProducto.val = -1;
                throw;
            }
            finally
            {
                dr.Close();
                cn.Close();
            }
            return lstProducto;

        }
    }
}
